<?php

namespace Part02_StrategyMode\Code6;

class CashReturn extends CashSuper
{
    /**
     * @var float 返利门槛
     */
    private $moneyCondition;

    /**
     * @var float 返利金额
     */
    private $moneyReturn;

    /**
     * 初始化的时候传入返利门槛和返利金额
     * CashReturn constructor.
     * @param $moneyCondition
     * @param $moneyReturn
     */
    public function __construct($moneyCondition, $moneyReturn)
    {
        $this->moneyCondition = $moneyCondition;
        $this->moneyReturn = $moneyReturn;
    }

    /**
     * @param float $money
     * @return float
     * @date: 2021/9/10
     * @desc: 按比例返回现金
     */
    public function acceptCash($money)
    {
        $result = $money;
        if ($money > $this->moneyCondition) {
            $result = $money - round(($money / $this->moneyCondition) * $this->moneyReturn, 2);
        }
        return $result;
    }

}